//返回格式化后的日期字符串，格式主要是yyyy MM dd HH mm ss W的任意组合
Date.prototype.format = function(formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];
    str = str.replace(/yyyy|YYYY/, this.getFullYear());
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));
    var month = this.getMonth() + 1;
    str = str.replace(/MM/, month > 9 ? month.toString() : '0' + month);
    str = str.replace(/M/g, month);
    str = str.replace(/w|W/g, Week[this.getDay()]);
    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
    str = str.replace(/d|D/g, this.getDate());
    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
    str = str.replace(/h|H/g, this.getHours());
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
    str = str.replace(/m/g, this.getMinutes());
    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
    str = str.replace(/s|S/g, this.getSeconds());
    return str;
}

//去掉首尾的空格
String.prototype.trim = function() { return (this.replace(/^\s+|\s+$/g, '')); }
//返回字符串的实际长度, 一个汉字算2个长度
String.prototype.len = function() {
    var str = this;
    return str.replace(/[^\x00-\xff]/g, "**").length;
}
//参数替换，在一个带有参数的字符串，可传入多个参数，按顺序替换
String.prototype.format = function(strs) {
    var str = this;
    for (var a = 0; a < strs.length; a++) { var reg = new RegExp("\\{" + a + "\\}", "g"); str = str.replace(reg, strs[a]); }
    return str;
}
//把字符串转变为日期格式，可返回定制的日期格式
String.prototype.toDate = function(formatStr) {
    var reg = /^(\d+)-(\d+)-(\d+)( (\d+):(\d+):(\d+))?$/;
    var r = this.match(reg);
    if (r == null) return "";
    r[2] = r[2] - 1;
    if (r[4].trim() == "") { r[5] = 0; r[6] = 0; r[7] = 0; }
    var d = new Date(r[1], r[2], r[3], r[5], r[6], r[7]);
    return d.format(formatStr);
}
//获取最左的前N个字，并返回是否带省略号
String.prototype.left = function(len, bdot) {
    var str = this;
    if (bdot == 'undefined') { bdot = false; }
    if (str.length <= len) { return str; }
    str = str.substr(0, len);
    if (bdot) { str += "..."; }
    return str;
}
//验证开始的格式
String.prototype.startWith = function(format) {
    var str = this;
    var ruleStr = "^" + format;
    var regExp = new RegExp(ruleStr, "ig");
    return regExp.test(str);
}
//返回字符串是否为空OrNull
String.prototype.isNullOrEmpty = function() {
    var str = this;
    if (str == null) { return true; }
    if (str.replace(/^\s+|\s+$/g, '') == '') { return true; }
    return false;
}
//返回字符串是否符合某个正则匹配
String.prototype.isMatched = function(ruleStr, ruleSet) {
    var str = this;
    if (ruleSet == null || ruleSet == "" || ruleSet == "undefined") { ruleSet = "ig"; }
    var regExp = new RegExp(ruleStr, ruleSet);
    return regExp.test(str);
}
//判断是否是URL地址
String.prototype.isUrl = function() {
    var str = this;
    var regExp = /^(http(s)?|ftp):\/\/([\w-]+\.)+[\w]+(\/[\w\W]*)?$/i;
    return regExp.test(str);
}


var _____IE = document.all ? true : false;
var SoDao = {
    //设置Cookie和获取Cookie，Cookie名不存在返回'undefined'
    getCookie: function(sName) { var aCookie = document.cookie.split('; '); for (var i = 0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split('='); if (sName == aCrumb[0]) { if (aCrumb[1] != null && aCrumb[1] != 'undefined') { return unescape(aCrumb[1]); }; return ''; } }; return undefined; },
    setCookie: function(sName, sValue, minutesKeep) { var now = new Date(); var expireTime = new Date(now.getTime() + minutesKeep * 60000); document.cookie = sName + '=' + escape(sValue) + '; path=/; expires=' + expireTime.toGMTString() + ';'; },
    //功能描述：获得文档
    getDocumentElement: function() {
        return (document.compatMode != "CSS1Compat") ? document.body : document.documentElement;
    },
    //功能描述：当前浏览器名，包括版本号,例如：FireFox 3.0, MSIE 7.0, Opera 8.0, Chrome 3.0
    getBrowser: function() {
        var str = navigator.userAgent.match(/MSIE\s*\d+\.\d+/ig);
        if (str == null) { str = navigator.userAgent.match(/FireFox\/?\s*\d+\.\d+/ig); }
        if (str == null) { str = navigator.userAgent.match(/Chrome\/?\s*\d+\.\d+/ig); }
        if (str == null) { str = navigator.userAgent.match(/Opera\/?\s*\d+\.\d+/ig); }
        if (str == null) { str = navigator.userAgent.match(/Safari\/?\s*\d+\.\d+/ig); }
        if (str != null) { return str.replace('/', ' '); }
        return '未知';
    },
    //功能描述：当前操作系统名称
    getOSName: function() {
        var str = navigator.userAgent.split(';')[2];
        var os = "未知";
        if (str.indexOf("NT 6.0") > 0) { os = "Windows 2008"; }
        else if (str.indexOf("NT 5.2") > 0) { os = "Windows 2003"; }
        else if (str.indexOf("NT 5.1") > 0) { os = "Windows XP"; }
        else if (str.indexOf("NT 5") > 0) { os = "Windows 2000"; }
        else if (str.indexOf("NT 4") > 0) { os = "Windows NT4"; }
        else if (str.indexOf("Mac") > 0) { os = "Mac"; }
        else if (str.indexOf("Unix") > 0) { os = "UNIX"; }
        else if (str.indexOf("Linux") > 0) { os = "Linux"; }
        else if (str.indexOf("Sun") > 0) { os = "SunOS"; }
        else if (str.indexOf("Me") > 0) { os = "Windows Me"; }
        else if (str.indexOf("98") > 0) { os = "Windows 98"; }
        else if (str.indexOf("95") > 0) { os = "Windows 95"; }
        return os;
    },
    //功能描述：当前浏览器简称名
    browserName: function() {
        var browser = '';
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf("msie") > -1) { browser = 'IE'; }
        else if (ua.indexOf("gecko") > -1) { browser = 'GECKO'; }
        else if (ua.indexOf("opera") > -1) { browser = 'OPERA'; }
        return browser;
    },
    //功能描述：获取 url 的参数值，不区分大小写,如无此参数，返回空字符串.
    getqueryparm: function(paras) {
        var url = location.href;
        var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
        var paraObj = {}; for (i = 0; j = paraString[i]; i++) {
            paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
        } var returnValue = paraObj[paras.toLowerCase()]; if (typeof (returnValue) == "undefined") { return ""; } else { return returnValue; }
    },
    //获取对象
    G: function(objId) { return document.getElementById(objId) },
    //获取对象数组
    GList: function(objName) { return document.getElementsByName(obj) },
    //获取对象样式对象
    GS: function(objId) { return document.getElementById(obj).style; },
    //获取字符串长度,汉字算两个字符长度
    getLength: function(s) {
        s = s.toString();
        var ret = true;
        var len = 0;
        for (var i = 0; i < s.length; i++) { len++; if (s.charCodeAt(i) >= 255) { len++; } }
        return len;
    },
    //去掉前空格
    LTrim: function(str) { return str.replace(/^\s+/g, ''); },
    //去掉后空格
    RTrim: function(str) { return str.replace(/\s+$/g, ''); },
    //判断是否为空    
    isEmpty: function(str) {
        if (str.toString().replace(/^\s+|\s+$/g, '') == '') { return true; }
        else { return false; }
    },
    //将选中的checkbox　拼成字符串    
    getCheckBoxValues: function(checkboxName, splitStr) {
        var append_str = "";
        if (splitStr == '') { splitStr = ','; }
        var chklist = this.$$(checkboxName);
        for (var i = 0; i < chklist.length; i++) {
            if (chklist[i].checked) {
                if (append_str == "") { append_str = chklist[i].value; }
                else { append_str += splitStr + chklist[i].value; }
            }
        }
        return append_str;
    },
    //加入收藏夹    
    addBookmark: function(title, url) {
        if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
        else if (document.all) { window.external.AddFavorite(url, title); }
        else if (window.opera && window.print) { return true; }
    },
    //加入剪贴板    
    copyToClipboard: function(txt, allowAlert) {
        if (window.clipboardData) {
            window.clipboardData.clearData();
            window.clipboardData.setData("Text", txt);
        }
        else if (navigator.userAgent.indexOf("Opera") != -1) {
            window.location = txt;
        }
        else if (window.netscape || navigator.userAgent.indexOf("Chrome") != -1) {
            alert("您的浏览器不支持脚本复制,请尝试手动复制");
            return false;
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                //alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");                
            }
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip)
                return;
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans)
                return;
            trans.addDataFlavor('text/unicode');
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext = txt;
            str.data = copytext;
            trans.setTransferData("text/unicode", str, copytext.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip)
                return false;
            clip.setData(trans, null, clipid.kGlobalClipboard);
        }
        if (allowAlert) { sDialog.message("复制成功！", "提示", 2000); }
    },
    //加入剪贴板    返回是否复制成功
    copyToClipboard2: function(txt) {
        if (window.clipboardData) {
            window.clipboardData.clearData();
            window.clipboardData.setData("Text", txt);
        }
        else if (navigator.userAgent.indexOf("Opera") != -1) {
            window.location = txt;
        }
        else if (window.netscape || navigator.userAgent.indexOf("Chrome") != -1) {
            return false;
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                //alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");                
            }
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip)
                return false;
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans)
                return false;
            trans.addDataFlavor('text/unicode');
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext = txt;
            str.data = copytext;
            trans.setTransferData("text/unicode", str, copytext.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip)
                return false;
            clip.setData(trans, null, clipid.kGlobalClipboard);
        }
        return true;
    },
    /*****************************************
    功能：显示一张图片自动适应高度、宽度
    ****************************************/
    DrawImage: function(imgId, iwidth, iheight) {
        var img = imgId;
        if (typeof imgId == "string") {
            img = document.getElementById(imgId);
        }
        if (img != null) {
            var image = new Image();
            image.src = img.src;
            if (image.width > 0 && image.height > 0) {
                if ((image.width * 1.0 / image.height) >= (iwidth * 1.0 / iheight)) {
                    if (image.width > iwidth) {
                        img.style.width = iwidth + "px";
                        img.style.height = image.height * iwidth * 1.0 / image.width + "px";
                    }
                    else {
                        img.style.width = image.width + "px";
                        img.style.height = image.height + "px";
                    }
                } else {
                    if (image.height > iheight) {
                        img.style.height = iheight + "px";
                        img.style.width = image.width * iheight * 1.0 / image.height + "px";
                    }
                    else {
                        img.style.height = image.height + "px";
                        img.style.width = image.width + "px";
                    }
                }
            }
        }
    },
    DrawImage1: function(imgId, iwidth, iheight) {
        var img = imgId;
        if (typeof imgId == "string") {
            img = document.getElementById(imgId);
        }
        if (img != null) {
            var image = new Image();
            image.src = img.src;
            if (image.width > 0 && image.height > 0) {
                if ((image.width * 1.0 / image.height) >= (iwidth * 1.0 / iheight)) {
                    if (image.width > iwidth) {
                        img.style.width = iwidth + "px";
                        img.style.height = image.height * iwidth * 1.0 / image.width + "px";
                    }
                }
                else {
                    if (image.height > iheight) {
                        img.style.height = iheight + "px";
                        img.style.width = image.width * iheight * 1.0 / image.height + "px";
                    }
                }
            }
        }
    },
    DrawImage2: function(img, iwidth, iheight) {
        if (img != null) {
            var image = new Image();
            image.src = img.src;
            if (image.width > 0 && image.height > 0) {
                if ((image.width * 1.0 / image.height) >= (iwidth * 1.0 / iheight)) {
                    if (image.width > iwidth) {
                        img.style.width = iwidth + "px";
                        img.style.height = image.height * iwidth * 1.0 / image.width + "px";
                    }
                }
                else {
                    if (image.height > iheight) {
                        img.style.height = iheight + "px";
                        img.style.width = image.width * iheight * 1.0 / image.height + "px";
                    }
                }
            }
        }
    },
    DrawImage3: function(img, iwidth, iheight) {
        if (!window.XMLHttpRequest) {
            if (img != null) {
                if (img.width > iwidth) {
                    img.width = iwidth;
                }
                if (img.height > iheight) {
                    img.height = iheight;
                }
            }
        }
    },
    DrawImage4: function(img, iwidth, iheight) {
        if (!window.XMLHttpRequest) {
            DrawImage2(img, iwidth, iheight);
        }
    },
    ErrorImg: function(imgId) {
        var img = imgId;
        if (typeof imgId == "string") {
            img = document.getElementById(imgId);
        }
        if (img != null) {
            img.src = "http://img.mysodao.com/delete.png";
            img.style.height = "140px";
            img.style.width = "210px";
        }
    },
    ErrorImg2: function(img) {
        if (img != null) {
            img.src = "http://img.mysodao.com/delete.png";
            img.style.height = "140px";
            img.style.width = "210px";
        }
    },
    //用户名格式是否正确    
    isUserName: function(userName) {
        var re = /^[0-9a-zA-Z_]+$/;
        if (!re.test(userName)) { return false; }
        else { return true; }
    },
    //密码格式是否正确    
    isPassword: function(password) { return true; },
    //去除 script iframe link style    
    clearScript: function(str) {
        return str.replace(/<(script|link|style|iframe)(.|\n)*\/\1>\s*/ig, "");
    },
    getEvent: function(evt) {
        evt = evt || window.event;
        if (!evt && !_____IE) {
            var c = this.getEvent.caller;
            while (c) {
                evt = c.arguments[0];
                if (evt && Event == evt.constructor) { break; }
                c = c.caller;
            }
        }
        if (evt) { return evt; }
        else { return arguments.callee.caller.arguments[0]; }
    },
    /*获取客户端浏览器宽度*/
    getClientWidth: function() {
        var width;
        if (this.browserName == "IE") { width = this.getDocumentElement().offsetWidth - 2; }
        else { width = this.getDocumentElement().offsetWidth; }
        return width;
    },
    /*获取客户端浏览器高度*/
    getClientHeight: function() {
        var height;
        if (this.browserName == "IE") { height = this.getDocumentElement().offsetHeight - 4; }
        else { height = this.getDocumentElement().clientHeight; }
        return height;
    },
    //获取对象scrollLeft的值  
    getScrollLeft: function(doc) {
        doc = doc || document;
        return Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
    },
    //获取对象的scrollTop的值
    getScrollTop: function(doc) {
        doc = doc || document;
        return Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
    },
    //获取屏幕 x ,y     
    getXY: function() {
        var x, y;
        if (this.browserName == "IE") {
            x = event.clientX + document.body.scrollLeft;
            y = event.clientY + document.body.scrollTop;
        }
        else {
            var e = this.getEvent(); //arguments.callee.caller.arguments[0];
            x = e.pageX; y = e.pageY;
        }
        if (x < 0) { x = 0 }
        if (y < 0) { y = 0 }
        return { x: x, y: y }
    },
    //获取指定对象 top.left    
    getPos: function(el, pos) {
        try {
            var ipos = 0;
            while (el != null) { ipos += parseInt(el["offset" + pos]); el = el.offsetParent; }
            return ipos;
        }
        catch (ex) { }
    },
    //获取对象绝对坐标    
    getObjXY: function(el) {
        var _t = 0;
        var _l = 0;
        if (document.documentElement.getBoundingClientRect) {
            var box = el.getBoundingClientRect();
            var oDoc = el.ownerDocument;
            _t = box.top - 2 + this.getScrollTop(oDoc);
            _l = box.left - 2 + this.getScrollLeft(oDoc);
        } else {
            while (el.offsetParent) { _t += el.offsetTop; _l += el.offsetLeft; el = el.offsetParent; }
        }
        return { top: _t, left: _l };
    },
    //获取某个控件点击时弹出层的位置 atp=L 左对齐， R=右对齐    
    getLayerXYByObj: function(objId, layerWidth, alignType) {
        var x, y;
        var _l = 0, _t = 0;
        var obj = typeof objId == "object" ? objId : this.G(objId);
        var _at = obj;
        try {
            do { _at = _at.offsetParent; _l += _at.offsetLeft; _t += _at.offsetTop; }
            while (_at.tagName != "BODY" && _at.tagName != "HTML");
        } catch (e) { }
        if (alignType == 'R') {
            x = obj.offsetLeft + _l - layerWidth + obj.offsetWidth;
            if (parseInt(obj.style.left) + layerWidth > this.getClientWidth()) { x = this.getClientWidth() - layerWidth - 20; }
        }
        else { x = obj.offsetLeft + _l; }
        y = obj.offsetTop + _t + obj.offsetHeight;
        return [x, y];
    },
    //剩余文字提醒,返回JSON对象    
    getNLWords: function(objId, minNum, maxNum) {
        var len = this.G(objId);
        if (len < minNum) { return { "type": "need", "number": minNum - len }; }
        var num = maxNum - len;
        if (num <= 0) { num = 0; }
        return { "type": "left", "number": num };
    },
    //ff firefox、ie、opera  "Ctrl_Enter" if(isKeyTrigger(e,13,true)) submit();
    isKeyTrigger: function(e, keyCode) {
        var argv = this.isKeyTrigger.arguments;
        var argc = this.isKeyTrigger.arguments.length;
        var bCtrl = false;
        if (argc > 2) { bCtrl = argv[2]; }
        var bAlt = false;
        if (argc > 3) { bAlt = argv[3]; }
        var nav4 = window.Event ? true : false;
        if (typeof e == 'undefined') { e = event; }
        if (bCtrl && !((typeof e.ctrlKey != 'undefined') ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)) { return false; }
        if (bAlt && !((typeof e.altKey != 'undefined') ? e.altKey : e.modifiers & Event.ALT_MASK > 0)) { return false; }
        var whichCode = 0;
        if (nav4) whichCode = e.which;
        else if (e.type == "keypress" || e.type == "keydown") whichCode = e.keyCode;
        else whichCode = e.button;
        return (whichCode == keyCode);
    },
    //ctrl+enter 指定 按钮 提交 表单
    docKeyDownToSubmit: function(e, btn) {
        if (typeof e == 'undefined') { e = event; }
        if (this.browserName() == 'IE') {
            if (e.ctrlKey && e.keyCode == 13) { this.G(btn).click(); return; }
        } else {
            if (this.isKeyTrigger(e, 13, true)) { this.G(btn).click(); return; }
        }
    },
    //enter 指定 按钮 提交 表单
    docEnterKeyToSubmit: function(e, btn) {
        if (typeof e == 'undefined') { e = event; }
        if (this.browserName() == 'IE') {
            if (e.keyCode == 13) { this.G(btn).click(); return; }
        } else {
            if (this.isKeyTrigger(e, 13, false)) { this.G(btn).click(); return; }
        }
    },
    //编辑器 bodyKeyDown 设置 页面 状态值    
    saveValue: function(id, value) { this.G(id).value = value; },
    //设置 弹窗 宽 、高
    setThickBoxSize: function(w, h) {
        if (w > 0) {
            document.getElementById('TB_iframeContent').style.width = w + "px";
            document.getElementById('TB_title').style.width = w + "px";
        }
        if (h > 0) { document.getElementById('TB_iframeContent').style.height = h + "px"; }
    },
    //添加事件    
    addEvent: function(obj, evt, func) {
        if (obj.attachEvent) { obj.attachEvent("on" + evt, func); }
        else if (obj.addEventListener) { obj.addEventListener(evt, func, false); }
        else { return false; }
        return true;
    },
    //移除事件    
    removeEvent: function(obj, evt, func) {
        if (obj.removeEventListener) { obj.removeEventListener(evt, func, false); }
        else if (obj.detachEvent) { obj.detachEvent('on' + evt, func); }
    },
    //获得坐标    
    getCoords: function(ev) {
        ev = ev || window.event;
        var el = SoDao.getDocumentElement();
        if (ev.pageX) return { x: ev.pageX, y: ev.pageY };
        return {
            x: ev.clientX + el.scrollLeft - el.clientLeft,
            y: ev.clientY + el.scrollTop - el.clientTop
        };
    },
    //拖动事件 
    //author:zsm
    //mousedownObj:鼠标按下对象
    //moveObj:移动对象
    //func:回调    
    dragObj: function(mousedownObj, moveObj, func) {
        mousedownObj.onmousedown = function(event) {
            if (SoDao.browserName() != 'IE') event.preventDefault();
            var ev = event || window.event;
            var pos = SoDao.getCoords(ev);
            var objTop = parseInt(moveObj.style.top); var objLeft = parseInt(moveObj.style.left);
            var objWidth = parseInt(moveObj.style.width); var objHeight = parseInt(moveObj.style.height);
            var mouseTop = pos.y; var mouseLeft = pos.x; var dragFlag = true;
            var moveListener = function(event) {
                if (dragFlag) {
                    var ev = event || window.event; var pos = SoDao.getCoords(ev);
                    var top = pos.y - mouseTop; var left = pos.x - mouseLeft;
                    func(objTop, objLeft, objWidth, objHeight, top, left);
                }
                return false;
            };
            var upListener = function(event) {
                dragFlag = false; return;
                SoDao.removeEvent(document, 'mousemove', moveListener);
                SoDao.removeEvent(document, 'mouseup', upListener);
            };
            SoDao.addEvent(document, 'mousemove', moveListener);
            SoDao.addEvent(document, 'mouseup', upListener);
        };
    },
    /**************************************************
    * *功能描述：当前时间
    **************************************************/
    getdatetime: function() {
        var todaytime = new Date();
        return todaytime.getHours() + "_" + todaytime.getMinutes() + "_" + todaytime.getSeconds();
    },
    /**************************************************
    * *功能描述：获取子字符串，中英文
    **************************************************/
    getSubString: function(str, leng) {
        while (str.replace(/[^\x00-\xFF]/g, "aa").length > leng) {
            str = str.substr(0, str.length - 1);
        }
        return str;
    },
    NulOrUndef: function(obj) {
        if (typeof obj == 'undefined' || obj == null)
            return true;
        return false;
    },
    URIEncode: function(text) {
        if (SoDao.NulOrUndef(text))
            return '';
        if (!SoDao.NulOrUndef(encodeURIComponent)) {
            return encodeURIComponent(text);
        }
        else {
            return escape(text);
        }
    },
    URIDecode: function(text) {
        if (SoDao.NulOrUndef(text))
            return '';
        if (!SoDao.NulOrUndef(decodeURIComponent)) {
            return decodeURIComponent(text);
        }
        else {
            return unescape(text);
        }
    },

    unescapeHTML: function(c) {

        c = c.trim();
        c = c.replace(/[\r\n]/ig, "");
        c = c.replace(/[\r]/ig, "");
        c = c.replace(/[\n]/ig, "");
        c = c.replace(/&lt;/ig, "<");
        c = c.replace(/&gt;/ig, ">");
        c = c.replace(/&quot;/ig, "\"");
        c = c.replace(/&#039;/ig, "'");
        c = c.replace(/&amp;/ig, "&");

        return c;

    },
    /**
    *HTML转换成文本 
    * @param string
    * @return 
    * 
    */
    escapeHTML: function(c) {
        c = c.replace(/<br>/ig, "");
        c = c.replace(/(\n)/ig, "");
        c = c.replace(/(\r|\n)/ig, "");
        c = c.replace(/</ig, "&lt;");
        c = c.replace(/>/ig, "&gt;");
        c = c.replace(/'/ig, "&#039;");
        c = c.replace(/"/ig, "&quot;");
        //  c = c.replace(/,/ig, "，");
        c = c.replace(/&/ig, "&amp;");
        return c;

    },
    /************
    .NET时间返回JSON转为JS时间格式
    *************/
    dataFilter: function(data) {

        return data.replace(/\/(Date\([0-9-]+\))\//gi, 'new $1');
    },
    /************
    .获取鼠标所在图片区域
    *************/
    getMousePositionMsg: function(img) {
        var x = this.getXY().x;
        var left = this.getObjXY(img).left;
        if (x < (left + img.offsetWidth / 2)) {
            return "left";
        } else {
            return "right";
        }
    }

};
//分页控件8
var sodaopager = function(container) {

    var sd_pager = this;
    this.firstText = "首页";
    this.prevText = "上一页";
    this.nextText = "下一页";
    this.lastText = "尾页";
    this.totalText = "共<em>{0}</em>条记录";
    this.showPageButtons = 4;
    this.showFirst = true;
    this.showLast = true;
    this.currentCss = "current";
    this.linkCss = "page";
    this.prevnextCss = "turn";
    this.totalTextCss = "cutPage-statistics";
    this.totalRows = 0;
    this.pageSize = 10;
    this.currentPage = 1;
    this.showPrevNext = true;
    this.showNumButtons = true;
    this.showTotalTip = true;
    this.callBack = null;
    this.wrapper = container;
    this.pageClick = function(pg) { };

    this.addButton = function(txt, css, pg) {
        var _pgbtn = document.createElement("a");
        _pgbtn.href = '#';
        _pgbtn.className = css;
        _pgbtn.innerHTML = txt;
        _pgbtn.setAttribute("page", pg);
        if (sd_pager.currentPage != pg) {
            _pgbtn.onclick = function() { var pg = parseInt(this.getAttribute("page")); sd_pager.pageClick(pg); return false; };
        }
        else
            _pgbtn.onclick = function() { return false; };
        container.appendChild(_pgbtn);
    }
    this.addTextButton = function(txt, css) {
        var _pgbtn = document.createElement("a"); _pgbtn.className = css; _pgbtn.innerHTML = txt; container.appendChild(_pgbtn);
    }
    this.addCurrentPage = function(txt) {
        var _pgbtn = document.createElement("b"); _pgbtn.innerHTML = txt; container.appendChild(_pgbtn);
    }
    this.addTotalText = function(txt, css) {
        var _spnTotal = document.createElement("span"); _spnTotal.className = css; _spnTotal.innerHTML = txt; container.appendChild(_spnTotal);
    }
    this.output = function() {
        container.innerHTML = '';
        if (this.totalRows > 0) {
            if (this.showTotalTip) {
                this.addTotalText(this.totalText.replace("{0}", this.totalRows), this.totalTextCss);
            }
            var _ttps = parseInt(this.totalRows / this.pageSize);
            if (this.totalRows % this.pageSize > 0) { _ttps++; }
            if (_ttps == 1)
                return;
            var _start = this.currentPage - this.showPageButtons;
            if (_start <= 0) { _start = 1; }
            var _end = this.currentPage + this.showPageButtons;
            if (_end > _ttps) { _end = _ttps; }

            var _pgbtn = null;
            if (_start >= 2 && this.showFirst) { this.addButton(this.firstText, this.linkCss, 1); }

            if (this.showPrevNext && this.currentPage > 1) {
                if (this.currentPage - 1 <= 0) { this.addButton(this.prevText, this.linkCss, 1); }
                else { this.addButton(this.prevText, this.linkCss, this.currentPage - 1); }
            }
            if (this.showNumButtons) {
                if (_start > 2 || (_start == 2 && !this.showFirst)) { this.addTextButton('...', this.linkCss); }
                for (var i = _start; i <= _end; i++) {
                    if (i == this.currentPage) { this.addCurrentPage(i); }
                    else { this.addButton(i, this.linkCss, i); }
                }
                if (_end < _ttps) { this.addTextButton('...', this.linkCss); }
            }
            if (this.showPrevNext && this.currentPage < _ttps) {
                if (this.currentPage + 1 > _ttps) { this.addButton(this.nextText, this.linkCss, _ttps); }
                else { this.addButton(this.nextText, this.linkCss, this.currentPage + 1); }
            }
            if (this.showLast && _end < _ttps)
                this.addButton(this.lastText, this.linkCss, _ttps);
        }
    }
};
function NodeClass() {    //定义一个节点类
    var prevNode=NULL;      //前驱指针
    var nextNode=NULL;      //后继指针 
    var nodeValue=NULL;     //节点值
}
//双向链表
var DoubleLinkedList = {
    l_Array : null,
    Initalize : function(){     //初始化一个双向链表
        this.l_Array = new NodeClass();
        return l_Array;
    },
    Length : function(){   //获得一个双向链表的元素个数
        var returnValue=0;
        var currenNode=this.l_Array;
        while(currentNode!=NULL){ //没有达到尾指针
           returnVlue++;          //计数累加
           currentNode=currentNode.nextNode; //指向下一个元素
        }
        return returnValue;
    },
    Get : function(i){     //取得一个双向链表中位序为i的元素
        var returnValue=NULL;
        var currentNode=this.l_Array;
        var currentIndex=0;
        while(currentNode!=NULL && currentIndex<=i){   //没有达到最后一个元素，并且位序小于或等于i
           if (currentIndex==i) 
           {
                returnValue=currentNode.nodeValue; //如果序号相等则返回
           }
           currentIndex++;
           currentNode=currentNode.nextNode;     //指向下一个元素
        }
        return returnValue;
    },
    Prior : function(elem){     //取得一个双向链表中值为elem的前一个元素的
        var returnValue=NULL;
        var currentNode=this.l_Array;
        while(currenNode!=NULL){
           if(currentNode.nodeValue==elem){ //判断当前值是否与给定的值相等
            if(currentNode.prevNode!=NULL){ //如果相同，并且不是第一个元素
             returnValue=currentNode.prevNode.nodeValue;//就将该元素的前一个元素返回
            }
            break;          //任务完成，退出循环
           }
           currentNode=currentNode.nextNode; //指向下一个元素
        }
        return returnValue;
    },
    Next : function(elem){    //取得一个双向链表中值为elem的后一个元素的值
        var returnValue=NULL;
        var currentNode=this.l_Array;
        while (currentNode!=NULL){ //只要没有到达尾指针
           if(currentNode.nodeValue==elem){ //如果与给定的元素相等
            if(currentNode.nextNode!=NULL){ //并且不是最后一个元素
             returnValue=currentNode.nextNode.nodeValue;   //将该元素的下一个元素的值返回
            }
            break;   // 任务完成，退出循环
           }
           currentNode=currentNode.nextNode; //指向下一个元素
        }
        return returnValue;
    },
    Loate : function (elem){        //取得一个双向链表中值为X的元素的位序
        var returnValue=NULL;
        var currentNode=this.l_Array;
        var currentIndex=0;
        while(currentNode!=NULL){      //只要没有达到尾指针
           if(currentNode.nodeValue==elem){ //如果与给定的值相等
            returnValue=currentIndex;   //将当前元素的序号返回
            break;   //任务完成，退出循环 
           }
           currentIndex++;    //累加序号
           currentNode=currentNode.nextNode; //指向下一个元素
        }
        return returnValue;
    },
    Insert : function(i,b){                //向一个双向链表的第i个位置插入值为b的元素
        var returnValue=this.l_Array;
        var currentNode=this.l_Array;
        var currentIndex=0;
        while(currentNode!=NULL){    //只要没有到达尾指针
           if (currentIndex==i){    //到达第i个元素
            var tempNode=new nodeClasss();
            if(currentNode.prevNode==NULL){ //第i个元素就是第一个元素
             tempNode.nextNode=currenNode; //插入到原链表中的第一个元素之前
             currentNode.prevNode=tempNode;
             this.l_Array=tempNode;               // 更新链表入口
           } else{
             //如果第i个元素不是原链表中的第一个元素
             //插入点前后元素的前后指针都要发生变化
             tempNode.prevNode=currentNode.prevNode;
             tempNode.nextNode=currentNode;
             currentNode.prevNode.nextNode=tempNode;
             currentNode.prevNode=tempNode;
            }
            tempNode.nodeValue=b;   //设置其值
            break;
           }
           currentIndex++;
           currentNode=currentNode.nextNode;    //指向下一个元素
        }
        return this.l_Array;
    },
    Delete : function(i){
        var returnValue=this.l_Array;
        var currentNode=this.l_Array;
        var currentIndex=0;
        while(currentNode!=NULL){ //如果没有到达尾指针
           if (currentIndex==i){ //到达了将要删除的元素的位置
                if(currentNode.nextNode==NULL){ //如果要删除的元素是最后一个元素
                 currentNode.prevNode.nextNode=NULL;
                }
                else if(currentNode.prevNode==NULL){   //如果删除的元素是第一个元素
                  currentNode.nextNode.prevNode=NULL;
                  this.l_Array=currentNode.nextNode;
                }
                else{
                 //如果既不是第一个元素也不是最后一个元素,那么删除该元素
                 currentNode.prevNode.nextNode=currentNode.nextNode;
                 currentNode.nextNode.prevNode=currentNode.prevNode;
                }
                break; //任务完成，跳出循环
            }
        }
        return returnValue;
    },
    Empty : function(){   //判断一个双向链表是否为空
        var returnValue=false;
        //前驱节点和后继节点都不存在即为空
        if(this.l_Array.prevNode==NULL && this.l_Array.nextNode==NULL)
            returnValue=true;
        return returnValue;
    },
    Clear : function(){
        var returnValue=true;
        this.l_Array.nextNode=NULL; //将首节点的后继节点置为NULL
        return returnValue;
    }
};

/*获取地址栏中HASH对应值*/
function GetUrlHashValue(key) {
    var nhash = window.location.hash;
    var m, value;
    switch (key) {
        case "p":
            m = nhash.match(/p=(\d+)&?/);
            if (m != null)
                value = RegExp.$1;
            else
                value = "1";
            break;
        case "g":
            m = nhash.match(/g=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = "lgb_all";
            break;
        case "kw":
            m = nhash.match(/kw=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "code":
            m = nhash.match(/code=(\d+)&?/);
            if (m != null)
                value = RegExp.$1;
            else
                value = null;
            break;
        case "s1":
            m = nhash.match(/s1=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "s2":
            m = nhash.match(/s2=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "s3":
            m = nhash.match(/s3=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "s4":
            m = nhash.match(/s4=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "s5":
            m = nhash.match(/s5=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
        case "s6":
            m = nhash.match(/s6=([^&]+)/)
            if (m != null)
                value = decodeURIComponent(RegExp.$1);
            else
                value = null;
            break;
    }

    return value;
};


/*
设置地址栏中HASH对应键值
obj = { p:1,g:xxx,kw:xxx }
*/
function SetUrlHashValue(obj) {

    //p:页码,g:分组(好友时用到),kw:一些查询条件
    
    var nhash;
    var p = obj.p ? obj.p == "" ? 1 : obj.p : GetUrlHashValue("p");
    var g = obj.g != null  ? obj.g : GetUrlHashValue("g");
    var kw = obj.kw != null  ? obj.kw : GetUrlHashValue("kw");
    var code = obj.code != null  ? obj.code : GetUrlHashValue("code");
    var s1 = obj.s1 != null  ? obj.s1 : GetUrlHashValue("s1");
    var s2 = obj.s2 != null ? obj.s2 : GetUrlHashValue("s2");
    var s3 = obj.s3 != null  ? obj.s3 : GetUrlHashValue("s3");
    var s4 = obj.s4 != null  ? obj.s4 : GetUrlHashValue("s4");
    var s5 = obj.s5 != null  ? obj.s5 : GetUrlHashValue("s5");
    var s6 = obj.s6 != null ? obj.s6 : GetUrlHashValue("s6");
    
    nhash = "#p=" + p;
    if (g) {
        nhash += "&g=" + encodeURIComponent(g);
    }

    if (kw) {
        nhash += "&kw=" + encodeURIComponent(kw);
    }

    if (code) {
        nhash += "&code=" + code;
    }
    
    if (s1) {
        nhash += "&s1=" + encodeURIComponent(s1);
    }

    if (s2) {
        nhash += "&s2=" + encodeURIComponent(s2);
    }

    if (s3) {
        nhash += "&s3=" + encodeURIComponent(s3);
    }

    if (s4) {
        nhash += "&s4=" + encodeURIComponent(s4);
    }

    if (s5) {
        nhash += "&s5=" + encodeURIComponent(s5)
    }
    if (s6) {
        nhash += "&s6=" + encodeURIComponent(s6);
    }
    
    window.location.hash = nhash;
};